
    //页面js代码
    (function () {
        //修复active失效的问题
        document.body.addEventListener('touchstart', function () {
        });
        //组件自动加载
        window.__setupCom = function (root) {
            var root = root || document.body;
            var doms = root.querySelectorAll("[data-com]");
            var cc = [];
            var deps = [];
            for (var i = 0; i < doms.length; i++) {
                var comName = "amd_common/" + doms[i].attributes["data-com"].value + ".js";
                var index = deps.indexOf(comName);
                if (index == -1) {
                    index = deps.length;
                    deps.push(comName);
                }
                cc.push({name: name, dom: doms[i], index: index});
            }
            require(deps, function () {
                for (var i = 0; i < cc.length; i++) {
                    cc[i].dom.coms = cc[i].dom.coms || [];
                    cc[i].dom.coms[cc[i].name] = new arguments[cc[i].index](cc[i].dom);
                }
            });
        }
        if ("require" in window) {
            __setupCom(document)

                } else {
//            var script = document.createElement('script');
//                script.src = 'booking_find.js';
//            script.async = 'async';
//            document.body.appendChild(script);
        }
        //导航条
        var nav = document.getElementsByClassName('nav-dropdown-btn')[0];
        var dropdown = document.getElementsByClassName('nav-dropdown')[0];
        if (dropdown) {
            nav.addEventListener('click', function (e) {
                dropdown.classList.toggle('active');
                e.stopPropagation();
            });
            document.body.addEventListener('click', function () {
                dropdown.classList.remove('active');
            });
        }
    })();
    (function (a, b, c) {
        if (c in b && b[c]) {
            var d, e = a.location, f = /^(a|html)$/i, chref;
            a.addEventListener("click", function (a) {
                d = a.target;
                while (!f.test(d.nodeName))d = d.parentNode;
                "href"in d && (chref = d.href).replace(e.href, "").indexOf("#") && chref && (!/^[a-z\+\.\-]+:/i.test(chref) || chref.indexOf(e.protocol + "//" + e.host) === 0) && (a.preventDefault(), e.href = d.href)
            }, !1)
        }
    })(document, window.navigator, "standalone");
    
    
    //.nav > li:eq(0)，.nav > li:eq(1)，.nav > li:eq(2)分别是导航上的过滤菜单：时间，地点，默认排序
    $(".nav > li:eq(0)").click(function() {
        if($(this).hasClass("active")){
            disActive($(this),$(".category-wrapper"));
        } else{
            active($(this),$(".category-wrapper"),"50px");
        }
    });

    $(".nav > li:eq(1)").click(function() {
        if($(this).hasClass("active")){
            disActive($(this),$(".biz-wrapper"));
        } else{
            active($(this),$(".biz-wrapper"),"180px");
            //$("#dropdown_scroller").css('width','40%');
        }
    });

    $(".nav > li:eq(2)").click(function() {
        if($(this).hasClass("active")){
            disActive($(this),$(".brand-wrapper"));
        } else{
            active($(this),$(".brand-wrapper"),"50px");
        }
    });

    /**
     * This method will add class(".active") to those elements whitch in param.
     * li: the nav filter menu(include 时间，地点，默认排序).
     * area: pannel when li menu is clicked.
     * height: the pannel height.
     */
    function active(li,area,height) {
        //$("#dropdown_scroller").css('width','100%');
        $(".nav > li").removeClass("active");
        $(".category-wrapper").removeClass("active");
        $(".biz-wrapper").removeClass("active");
        $(".brand-wrapper").removeClass("active");
        
        li.addClass("active");
        $(".dropdown-module").css("height",height);
        area.addClass("active");
        $(".shade").removeClass("hide");
    }
    function disActive(li,area){
        li.removeClass("active");
        $(".dropdown-module").css("height","0px");
        area.removeClass("active");
        $(".shade").addClass("hide");
    }
    
    /**
     * Below funciton will be called when nav time filter clicked.
     * #search-submit: the id of time filter li.
     */
    $("#search-submit").click(function() {
        var date1 = $("#appDate1").val();
        var date2 = $("#appDate2").val();
        if(date1 != "" || date2 != "") {
            var myDate = new Date();
            var theMonth = myDate.getMonth()+1;
            var nowDate = myDate.getFullYear()+"-"+theMonth+"-"+myDate.getDate();
            date1 = date1 ? date1 : nowDate;
            date2 = date2 ? date2 : nowDate;
            for(var index in $(".booking_date")){
                var date = $(".booking_date").eq(index).text();
                if(dateCompare(date,date1) && dateCompare(date2,date)){
                    $(".booking_date").eq(index).closest("dd").css("display","block");
                }else {
                    $(".booking_date").eq(index).closest("dd").css("display","none");
                }
            }  
        }else {
            $(".list > dd").css("display","block");
        }
        disActive($(".nav > li:eq(0)"),$(".category-wrapper"));
    });
    
    //compare date
    function dateCompare(startdate,enddate)   
    {     
        var arr=startdate.split("-");    
        var starttime=arr[0]+arr[1]+arr[2];    
        var starttimes=parseInt(starttime); 

        var arrs=enddate.split("-");    
        var lktime=arrs[0]+arrs[1]+arrs[2];    
        var lktimes=parseInt(lktime);   

        if(starttimes>=lktimes)     
            return true;    
        else  
            return false;
    }
    
    /**
     * Below funciton will be called when nav city filter clicked.
     */
    $(".biz-wrapper > ul > li").click(function() {
        $(this).siblings().removeClass("active");
        $(this).addClass("active");
        var chooseRegion = $(this).attr("data-biz-name");
        if(chooseRegion == "china.chongqing") {
            $(".list > dd").css("display","block");
        }else {
            for(var index in $(".booking_region")){
                var region = $(".booking_region").eq(index).text();
                if(chooseRegion == region){
                    $(".booking_region").eq(index).closest("dd").css("display","block");
                }else {
                    $(".booking_region").eq(index).closest("dd").css("display","none");
                }
            }
        }
        disActive($(".nav > li:eq(1)"),$(".biz-wrapper"));
    });